package multithread;

import java.util.HashMap;

/**
 * @Author: zhangrongqing
 * @Date: 2019/12/18 10:33
 */
public class ThreadLocalDemo {
//    private static ThreadLocal<ThreadLocalDemo> THRAD_DEMO_LOCAL = ThreadLocal.withInitial(ThreadLocalDemo::new);
    private static ThreadLocal<ThreadLocalDemo> THRAD_DEMO_LOCAL = new ThreadLocal<>();

    private HashMap<String,String> hashMap = new HashMap<>();

    public void put(String key,String value){
        hashMap.put(key,value);
    }

    public String get(String key){
        return hashMap.get(key);
    }

    public static ThreadLocalDemo getThreadLocal(){
        //放回当前线程的ThreadLocalDemo
        return THRAD_DEMO_LOCAL.get();
    }

    public static void setThreadLocal(ThreadLocalDemo threadLocalDemo){
        THRAD_DEMO_LOCAL.set(threadLocalDemo);
    }
}
